<?php
/**
 * 应用自定义控制器类
 * 
 * @version $Id: AdminController.php 291 2012-05-04 03:01:07Z linsir123 $
 */
class AdminController extends Controller 
{
	/**
	 * 控制器前置操作
	 */
	public function beforeAction()
	{
		if ( ! MA::admin()->isLogin()) 
			$this->r();
			
		///
		AdminView::init();
	}
	
	/**
	 * 路由跳转
	 */
	public function r($r = '', $return = false)
	{
		$r = 'admin/'.$r;
		if ($return) 
			return lpUrl::__($r);
			
		///
		lpUrl::_r($r);
	}
	
	/**
	 * 访问地址有误
	 */
	public function miss()
	{
		echo '访问地址有误';
		///
		App::end();
	}
	
	/**
	 * 输出内容
	 */
	public function ajax($content)
	{
		echo $content;
		///
		exit();
	}
	
	/**
	 * 提示(用于表单提交后进行数据提示)
	 * 
	 * @param string $content 待提示的内容
	 * @param int $type 提示状态码(0成功, 1失败)
	 * @param int $pop 是否是弹出层提交(0否, 1是, 2是(且回退))
	 * @param string $r 操作后是否进行页面跳转,有则为对应的路由,无则返回上一步
	 */
	public function tipMsg($content, $type = 0, $pop = 0, $r = null)
	{
		if (empty($pop) && empty($r)) 
			$r = 'main/welcome';
			
		///
		View::display('tip_js');
		View::assignSet(array(
			'content'=>$content,
			'url'=>(empty($r) ? '' : $this->r($r, true)),
			'type'=>$type,
			'pop'=>$pop
		));
		App::end();
	}
	
	/**
	 * 输出分页
	 */
	public function pagination($show, $count, $r)
	{
		$totalPage = ceil($count/$show);
		$page = intval($_GET['p']);
		if ($page <= 0) 
			$page = 1;
		if ($page >= $totalPage)
			$page = $totalPage;
			
		///
		$terms = array('first'=>'首页','pre'=>'上一页','next'=>'下一页','last'=>'尾页');
		$com = App::C('Pagination', null, $page, $totalPage, 8, $terms);
		$com->setAformat("<a url=\"". $this->r($r.'/p/%d', true) ."\" class=\"AIframe\">%s</a>");
		$pagination = $com->display();
		
		///
		View::assign('pagination', $pagination);
		View::assign('baseNum', ($page-1)*$show);
		return $page;
	}
}
